#include "widget.h"
#include "ui_widget.h"
#include "QTimer"
#include "QProgressBar"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //设置初始值
    //ui->lcdNumber->display(10);
    //timer = new QTimer(this);
    //connect(timer,&QTimer::timeout,this,&Widget::decTime);
    //timer->start(1000);

    ui->progressBar->setValue(0);
    //ui->progressBar->setMinimum(0);
    //ui->progressBar->setMinimum(100);

    timer1 = new QTimer(this);
    connect(timer1,&QTimer::timeout,this,&Widget::addProgress);
    timer1->start(100);

    ui->progressBar->setStyleSheet("QProgressBar::chunk { background : red;}");
}

//void Widget::decTime()
//{
//    int time = ui->lcdNumber->intValue();
//    if(time <= 0)
//    {
//        timer->stop();
//        return;
//    }
//    else
//        ui->lcdNumber->display(time - 1);
//}

void Widget::addProgress()
{
    int value = ui->progressBar->value();
    if(value >= 100)
    {
        timer1->stop();
        return;
    }
    else
    {
        ui->progressBar->setValue(value + 1);
    }
}


Widget::~Widget()
{
    delete ui;
}

